package com.xzy.a;

import com.xzy.service.BookService;
import com.xzy.service.CourseService;
import com.xzy.service.SchoolService;
import com.xzy.service.TeacherService;
import lombok.ToString;
import lombok.extern.slf4j.Slf4j;

/**
 * 依赖注入的方式：<property/> + set方法
 *
 * @author xzy
 * @date 2021/12/6 21:50
 */
@Slf4j
@ToString
public class AaaServiceImpl {

    /*
     * 通过<property>标签能够为Bean的属性手动设置注入的值：
     *
     * <bean id="xxx" class="xxx">
     *     <property name="xxx" ref="xxx">
     * </bean>
     *
     */

    private BookService bookService;
    private CourseService courseService;
    private SchoolService schoolService;
    private TeacherService teacherService;

    /*
     * 工作过程：
     *     Spring容器根据<property>标签中的name属性到Bean中寻找Set方法——方法名为setXxx()且参数个数为1，
     *     然后调用set方法将<property>标签中ref属性指定的依赖注入Bean。如果没有找到符合条件的set方法则抛出
     *     异常。
     *
     */

    public AaaServiceImpl() {
        log.info("实例化 => AaaServiceImpl()");
    }

    public void setBookService(BookService bookService) {
        this.bookService = bookService;
        log.info("依赖注入 -> {}", bookService);
    }

    public void setCourseService(CourseService courseService) {
        this.courseService = courseService;
        log.info("依赖注入 -> {}", courseService);
    }

    public void setSchoolService(SchoolService schoolService) {
        this.schoolService = schoolService;
        log.info("依赖注入 -> {}", schoolService);
    }

    public void setTeacherService(TeacherService teacherService) {
        this.teacherService = teacherService;
        log.info("依赖注入 -> {}", teacherService);
    }
}
